<?php
// no direct access
defined('_JEXEC') or die('Restricted Access');
?>

<ul id="MenuBar1" class="MenuBarVertical">
<?php foreach($options as $op) : ?>
<?php $link = JRoute::_('index.php?option=com_shop&view=category&id='.$op->id.':'.$op->alias); ?>
	<li>
    	<span class="listtitle"><a href="<?php echo $link; ?>"><?php echo $op->title; ?></a></span>
        <?php 
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->select('*');
		$query->from('#__shop_category');
		$query->where('parent_id ='.$op->id);
		$query->where('state = 1');
		$query->order('ordering ASC');
		
		// Get the options.
		$db->setQuery($query);
		$options1 = $db->loadObjectList();
		?>
        <?php if(count($options1) > 0) : ?>
        <ul>
			<?php foreach($options1 as $op1) : ?>
            <?php $link1 = JRoute::_('index.php?option=com_shop&view=category&id='.$op1->id.':'.$op1->alias); ?>
            <li><span class="listtitle"><a href="<?php echo $link1; ?>"><?php echo $op1->title; ?></a></span></li>
            <?php endforeach; ?>
        </ul>
        <?php endif; ?>
    </li>
<?php endforeach; ?>
</ul>